﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using OrderDocument;
using DataLayer;

namespace Manager
{
    public partial class frmMessage : XtraForm
    {
        public frmMessage()
        {
            InitializeComponent();
        }

        private void txtCariKod_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F10)
            {
                frmListe liste = new frmListe();
                liste.ListeTipi = frmListe.ListeTipleri.SupplierAdi;
                liste.Filtre = txtCariKod.Text;

                if (liste.ShowDialog(this) == DialogResult.OK)
                {
                    List<List<string>> val = liste.Value as List<List<string>>;
                    for (int i = 0; i < val[0].Count; i++)
                    {
                        txtCariKod.Text += val[0][i] + ";";
                        textBox1.Focus();
                        textBox1.Text = "";
                        i += 1;
                    }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtCariKod.Text))
            {
                string[] cariler = txtCariKod.Text.Substring(0, txtCariKod.Text.Length - 1).Split(';');
                if (cariler.Length > 0)
                {
                    foreach (string cari in cariler)
                    {
                        Factory.GetFactory.ExecuteNonQuery(string.Format("insert into MESSAGES (supplier,message,read_mark) values ('{0}','{1}',0)", cari, textBox1.Text));
                    }
                }
                textBox1.Text = string.Empty;
                txtCariKod.Text = string.Empty;
                txtCariKod.Focus();
            }
        }

        private void txtCariKod_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmListe liste = new frmListe();
            liste.ListeTipi = frmListe.ListeTipleri.SupplierAdi;
            liste.Filtre = txtCariKod.Text;

            if (liste.ShowDialog(this) == DialogResult.OK)
            {
                List<List<string>> val = liste.Value as List<List<string>>;
                for (int i = 0; i < val[0].Count; i++)
                {
                    txtCariKod.Text += val[0][i] + ";";
                    textBox1.Focus();
                    textBox1.Text = "";
                    i += 1;
                }
            }
        }
    }
}
